/**
 * Created by zhangligang
 * Email: tzhang2450@163.com
 * Date: 2018/11/24
 * Time: 05:53
 */
$(function(){
    var authorization = Cookies.get('_token');
    $('.btn-save').on('click', function(){
        var params = {
            old_pass: $('.old-pass').val(),
            new_pass: $('.new-pass').val(),
            new_pass_sec: $('.new-pass-sec').val()
        };
        if (checkForm(params)) {
            $.ajax({
                type: 'post',
                url: '/v1/manager/changePass',
                headers: {
                    Authorization: authorization,
                    Accept: "application/json; charset=utf-8"
                },
                data: {params: params},
                success: function(e){
                    var data = JSON.parse(e);
                    if (data.status == 200) {
                        alert('密码更新成功!');
                    }
                }
            });
        }
    })
});

function checkForm(params) {
    if (params.old_pass == '') {
        alert('请输入原密码!');
        return false;
    }
    if (params.new_pass == '') {
        alert('请输入新密码!');
        return false;
    }
    if (params.new_pass_sec == '') {
        alert('请输入确认新密码!');
        return false;
    }
    return true;
}